import { BasicColumn, FormSchema } from '@/components/Table';
import { h } from 'vue';
import { Switch, Image, Tag } from 'ant-design-vue';
import { supplierAllListApi } from '@/api/sys/wmProduct';
import { uploadApi, uploadImgApi } from '@/api/sys/upload';
import { useMessage } from '@/hooks/web/useMessage';
import FormSelectTable from '@/views/msManage/components/formSelectTable/index.vue';
import { style } from '@logicflow/extension/es/bpmn-elements/presets/icons';

type CheckedType = boolean | string | number;
export const columns: BasicColumn[] = [
  {
    title: '商品名称',
    dataIndex: 'name',
    width: 200,
  },
  {
    title: '商品编码',
    dataIndex: 'prodNumber',
    width: 200,
  },

  {
    title: '供应商',
    dataIndex: 'supplierName',
    width: 120,
  },
  {
    title: '成本价',
    dataIndex: 'costPrice',
    width: 100,
  },
  {
    title: '起售价',
    dataIndex: 'oriPrice',
    width: 100,
  },
  // {
  //   title: '库存',
  //   dataIndex: 'stock',
  //   width: 100,
  // },
  {
    title: '封面',
    dataIndex: 'pic',
    width: 120,
  },

  {
    title: '体积',
    dataIndex: 'volume',
    width: 100,
  },
  {
    title: '重量',
    dataIndex: 'weight',
    width: 100,
  },
  {
    title: '状态',
    dataIndex: 'status',
    width: 80,
    customRender: ({ record }) => {
      const status = record.status;
      const enable = ~~status === 1;
      const color = enable ? 'green' : 'red';
      const text = enable ? '启用' : '停用';
      return h(Tag, { color: color }, () => text);
    },
  },

  {
    title: '创建时间',
    dataIndex: 'createTime',
    width: 180,
  },
];

export const searchFormSchema: FormSchema[] = [
  {
    field: 'keyword',
    label: '商品名称',
    component: 'Input',
    colProps: { span: 5 },
  },
  {
    field: 'prodNumberLike',
    label: '商品编码',
    component: 'Input',
    colProps: { span: 5 },
  },
  {
    field: 'supplierNameLike',
    label: '供应商名称',
    component: 'Input',
    colProps: { span: 5 },
  },
  {
    field: 'status',
    label: '状态',
    component: 'Select',
    defaultValue: 1,
    componentProps: {
      options: [
        { label: '启用', value: 1 },
        { label: '停用', value: 0 },
      ],
    },
    colProps: { span: 5 },
  },
  // {
  //   label: '班级',
  //   field: 'clazzId',
  //   component: 'ApiSelect',
  //   componentProps: {
  //     api: clazzSelectsApi,
  //     resultField:"data",
  //     labelField: 'clazzName',
  //     valueField: 'clazzId',
  //   },
  //   colProps: { span: 6 },
  //
  // },
];
//: FormSchema[]
const baseFormSchema = [
  {
    field: '',
    label: '商品基本信息',
    component: 'divider',
    show: false,
  },
  {
    field: '',
    label: '',
    component: 'group',
    items: [
      {
        field: 'name',
        label: '商品名称',
        required: true,
        component: 'Input',
        colProps: {
          span: 11,
        },
      },

      {
        field: 'measureUnit',
        label: '计量单位',
        required: false,
        component: 'Input',
        placeholder: '参考单位(件/包/个)',
        colProps: {
          span: 11,
        },
      },
    ],
  },
  {
    field: '',
    label: '',
    component: 'group',
    items: [
      {
        field: 'prodNumber',
        label: '编号',
        required: false,
        component: 'div',
        colProps: {
          span: 2,
          offset: 2,
        },
      },
      {
        label: '供应商',
        field: 'supplierName',
        colProps: {
          span: 2,
          offset: 2,
        },
        component: 'ApiSelect',
        componentProps: {
          api: supplierAllListApi,
          resultField: 'data',
          labelField: 'supplierName',
          valueField: 'supplierName',
        },
        // component: 'SelectSupplierIndex',
        required: false,
      },
    ],
  },

  {
    field: '',
    label: '',
    component: 'group',
    items: [
      {
        field: 'picArr',
        label: '封面图',
        required: false,
        component: 'Upload',
        componentProps: {
          api: uploadImgApi,
          multiple: true,
          accept: ['.png', '.jpeg', '.jpg'],
          resultField: 'data.data',
          maxSize: 10,
          maxNumber: 30,
          previewDelete: function (res) {
            console.log(res);
          },
          delete: function (record) {
            console.log('--delete');
            console.log(record);
          },
          change: function (list) {
            console.log('--change');
            console.log(list);
          },
        },
        colProps: {
          span: 3,
        },
      },
      {
        field: 'picsArr',
        label: '详情-主图',
        required: false,
        component: 'Upload',
        componentProps: {
          api: uploadImgApi,
          multiple: true,
          accept: ['.png', '.jpeg', '.jpg'],
          resultField: 'data.data',
          maxSize: '10',
          maxNumber: '30',
          previewDelete: function (res) {
            console.log(res);
          },
          delete: function (record) {
            console.log('--delete');
            console.log(record);
          },
          change: function (list) {
            console.log('--change');
            console.log(list);
          },
        },
        colProps: {
          span: 3,
        },
      },
      {
        field: 'detailsArr',
        label: '详情-介绍图',
        required: false,
        component: 'Upload',
        componentProps: {
          api: uploadImgApi,
          multiple: true,
          accept: ['.png', '.jpeg', '.jpg'],
          resultField: 'data.data',
          maxSize: '10',
          maxNumber: '30',
          previewDelete: function (res) {
            console.log(res);
          },
          delete: function (record) {
            console.log('--delete');
            console.log(record);
          },
          change: function (list) {
            console.log('--change');
            console.log(list);
          },
        },
        colProps: {
          span: 3,
        },
      },
    ],
  },
  {
    field: '',
    label: '',
    component: 'group',
    items: [
      {
        field: 'costPrice',
        label: '成本价',
        component: 'InputNumber',
        required: false,
        colProps: {
          span: 13,
          offset: 2,
        },
      },
      {
        field: 'oriPrice',
        label: '起售价',
        component: 'InputNumber',
        required: true,
        colProps: {
          span: 13,
          offset: 2,
        },
      },
    ],
  },
  {
    field: '',
    label: '',
    component: 'group',
    items: [
      {
        field: 'baseNumber',
        label: '基础数量',
        component: 'InputNumber',
        required: false,
        componentProps: {
          style: { width: '92%' },
        },
        colProps: {
          span: 13,
          offset: 2,
        },
      },
    ],
  },

  {
    field: '',
    label: '',
    component: 'group',
    items: [
      {
        field: 'weight',
        label: '重量',
        component: 'InputNumber',
        required: false,

        colProps: {
          span: 13,
          offset: 2,
        },
      },
      {
        field: 'weightUnit',
        label: '重量单位',
        component: 'Input',
        colProps: {
          span: 13,
          offset: 2,
        },
      },
    ],
  },
  {
    field: '',
    label: '',
    component: 'group',
    items: [
      {
        field: 'volume',
        label: '体积',
        component: 'InputNumber',
        required: false,

        colProps: {
          span: 13,
          offset: 2,
        },
      },
      {
        field: 'volumeUnit',
        label: '体积单位',
        component: 'Input',
        colProps: {
          span: 13,
          offset: 2,
        },
      },
    ],
  },

  {
    field: 'materialNo',
    label: '物料编号',
  },

  // {
  //   label: '费用类型',
  //   field: 'costTypeId',
  //   component: 'ApiSelect',
  //   componentProps: {
  //     api: dictAllListApi,
  //     params:{type:1},
  //     resultField:"data",
  //     labelField: 'name',
  //     valueField: 'id',
  //   },
  //   required: true,
  // },
  {
    field: '',
    label: '规格信息',
    component: 'divider',
    show: false,
  },
  {
    field: '',
    label: '',
    component: 'group',
    items: [
      {
        field: 'skuObj',
        label: '规格',
        required: true,
        helpMessage: ['限制最多两组规格'],
        component: 'productSpecForm',
        colProps: {
          span: 13,
          offset: 2,
        },
      },
    ],
  },
];

export const formSchema = baseFormSchema;
